package org.luckyjourney.controller.residentconsultant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.luckyjourney.entity.ResidentConsultant;
import org.luckyjourney.entity.dto.ResidentConsultantDTO;
import org.luckyjourney.entity.vo.ResidentConsultantVO;
import org.luckyjourney.service.residentconsultant.ResidentConsultantService;
import org.luckyjourney.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/luckyjourney/consultant")
@Api(tags = "咨询师入住")
@Slf4j
public class ResidentConsultantController {

    @Autowired
    ResidentConsultantService residentConsultantService;


    @PostMapping("/insert")
    @ApiOperation("申请咨询师资格")
    public Result insert(@RequestBody @Validated ResidentConsultant residentConsultant) {
        log.info("申请咨询师资格");
        log.info("请求方式 Post");

        String insert = residentConsultantService.insert(residentConsultant);
        return Result.success(insert);
    }

    @PostMapping("/delect")
    @ApiOperation("删除申请资料")
//    @RequiresPermissions("byt:delect")
    public Result delect(@RequestBody ResidentConsultantDTO residentConsultantDTO) {
        log.info("删除申请资料");
        log.info("请求方式 Post");
        log.info("请求路径 /byt/delect");
        int i = residentConsultantService.delect(residentConsultantDTO);
        if(i>0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }


    @PostMapping("/update")
    @ApiOperation("更新申请资料")
    public Result updates(@RequestBody ResidentConsultant residentConsultant) {
        log.info("更新申请资料");
        log.info("请求方式 Post");
        log.info("请求路径 /byt/update");
        Boolean aBoolean = residentConsultantService.updates(residentConsultant);
        if(aBoolean==true){
            return Result.success("修改成功");
        }
        return Result.error("修改失败");
    }

    @PostMapping("/selectId")
    @ApiOperation("查看申请资料")
    public Result selectId(@RequestBody ResidentConsultantDTO residentConsultantDTO) {
        log.info("查看申请资料");
        log.info("请求方式 Post");
        log.info("请求路径 /byt/update");
        ResidentConsultantVO result = residentConsultantService.selectId(residentConsultantDTO);
        return Result.success(result);
    }
}
